package io.renren.modules.jxgkphone.dao;


import io.renren.modules.jxgkphone.entity.ClassCourse;
import io.renren.modules.jxgkphone.entity.DateInfo;
import io.renren.modules.jxgkphone.tempEntity.TempClass;
import io.renren.modules.jxgkphone.tempEntity.TempDAC;
import io.renren.modules.jxgkphone.tempEntity.TempDTAC;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Map;

/*
余沛然 班级课程信息
 */
@Repository
@Mapper
public interface ClassCourseMapper {

    @Select("SELECT * FROM course_date WHERE course_date=#{course_date}")
    DateInfo findDateInfoByDate(String date);
    @Select("select DISTINCT cc.course_name from class_course  cc where cc.class_name= #{classname}")
    List<String> getCourseByClass(@RequestParam Map<String, Object> params) ;
    @Select("SELECT class_course_id," +
            "course_teacher_name," +
            "course_classroom_position," +
            "course_name" +
            ",course_academic_year," +
            "course_academic_term," +
            "course_which_week," +
            "course_which_day," +
            "course_which_index," +
            "course_teacher_id, " +
            "is_attendance, " +
            "course_diary_state " +
            "FROM   class_course   WHERE " +
            "course_academic_year=#{courseAcademicYear} " +
            "AND course_academic_term=#{courseAcademicTerm} " +
            "AND course_which_week=#{courseWhichWeek} " +
            "AND class_name=#{studentClassName} " +
            "ORDER BY course_which_index")
    List<TempClass> studentWeekClassInfo(TempDAC ts);

    @Select("SELECT class_course_id," +
            "course_teacher_name," +
            "course_classroom_position," +
            "course_name," +
            "course_academic_year," +
            "course_academic_term," +
            "course_which_week," +
            "course_which_day," +
            "course_which_index," +
            "course_teacher_id, " +
            "is_attendance, " +
            "course_diary_state, " +
            "teach_content, " +
            "class_name " +
            "FROM   class_course   WHERE " +
            "course_academic_year=#{courseAcademicYear} " +
            "AND course_academic_term=#{courseAcademicTerm} " +
            "AND course_which_week=#{courseWhichWeek} " +
            "AND class_name=#{studentClassName} " +
            "AND course_which_day=#{courseWhichDay} " +
            "ORDER BY course_which_index")
    List<TempClass> studentDayClassInfo(TempDAC ts);
    @Select("SELECT class_course_id," +
            "course_teacher_name," +
            "course_classroom_position," +
            "course_name," +
            "course_academic_year," +
            "course_academic_term," +
            "course_which_week," +
            "course_which_day," +
            "course_which_index," +
            "course_teacher_id, " +
            "is_attendance " +
            "FROM   class_course   WHERE " +
            "course_diary_state=0 " +
            "AND course_diary_modified=1 " +
            "AND class_name= #{class_name}" +
            "ORDER BY course_which_index")
    List<TempClass> studentDiaryDayClassInfo(String class_name);
    @Select("SELECT class_course_id," +
            "course_teacher_name," +
            "course_classroom_position," +
            "course_name," +
            "course_academic_year," +
            "course_academic_term," +
            "course_which_week," +
            "course_which_day," +
            "course_which_index," +
            "course_teacher_id " +
            "FROM   class_course   WHERE " +
            "course_attendance_state=0 " +
            "AND course_attendance_modified=1 " +
            "AND class_name=#{class_name} " +
            "ORDER BY course_which_index")
    List<TempClass> studentAttendanceDayClassInfo(String class_name);

    @Select("SELECT course_date FROM course_date WHERE course_academic_year=#{courseAcademicYear}" +
            "AND course_academic_term=#{courseAcademicTerm} AND course_which_week=#{courseWhichWeek} AND " +
            "course_which_day=#{courseWhichDay}")
    String findDateByDateInfo(DateInfo date);
    @Select("SELECT course_date FROM course_date WHERE course_academic_year=#{courseAcademicYear}" +
            "AND course_academic_term=#{courseAcademicTerm} AND course_which_week=#{courseWhichWeek} AND " +
            "course_which_day=#{courseWhichDay}")
    List<String> findDateByDateInfoList(DateInfo date);
    @Select("SELECT * FROM class_course WHERE class_course_id=#{cid}")
    ClassCourse getCourseById(String cid);
    @Select("UPDATE class_course set is_attendance=#{isAttendance} where class_course_id=#{classCourseId}")
    void updateIsAttendance(ClassCourse classCourse);
    @Select("UPDATE class_course set course_diary_state=#{courseDiaryState} where class_course_id=#{classCourseId}")
    void updateCourseAttandanceState(ClassCourse classCourse);
    @Select("select teaching_week_num  FROM school_term where end_date>NOW() and NOW()>start_date")
    List<Integer> getThisTerm();


    @Select("SELECT class_course_id," +
            "course_teacher_name," +
            "course_classroom_position," +
            "course_name," +
            "class_name," +
            "course_academic_year," +
            "course_academic_term," +
            "course_which_week," +
            "course_which_day," +
            "course_which_index," +
            "course_teacher_id, " +
            "is_attendance, " +
            "course_diary_state, " +
            "teach_content " +
            "FROM   class_course   WHERE " +
            "course_academic_year=#{courseAcademicYear} " +
            "AND course_academic_term=#{courseAcademicTerm} " +
            "AND course_which_week=#{courseWhichWeek} " +
            "AND course_teacher_id=#{tacherId} " +
            "AND course_which_day=#{courseWhichDay} " +
            "GROUP BY class_name " +
            "ORDER BY course_which_index")
    List<TempClass> TeacherDayClassInfo(TempDTAC ts);


    @Select("SELECT class_course_id," +
            "course_teacher_name," +
            "course_classroom_position," +
            "course_name" +
            ",course_academic_year," +
            "course_academic_term," +
            "course_which_week," +
            "course_which_day," +
            "course_which_index," +
            "course_teacher_id, " +
            "is_attendance, " +
            "course_diary_state " +
            "FROM   class_course   WHERE " +
            "course_academic_year=#{courseAcademicYear} " +
            "AND course_academic_term=#{courseAcademicTerm} " +
            "AND course_which_week=#{courseWhichWeek} " +
            "AND course_teacher_id=#{tacherId} " +
            "ORDER BY course_which_index")
    List<TempClass> teacherWeekClassInfo(TempDTAC ts);

    List<String> findDate(Map<String,Object> params);
}
